#include <cstdlib>
#include <string>
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

class Solution {
public:
	int ctoi(char c){
		return c - '0';
	}
	bool isWhiteSpace(char c){
		return c == ' ' || c == '\t' || c == '\n';
	}
	bool isDigit(char c){
		return c >= '0' && c <= '9';
	}
	int atoi(string str) {
		int idx = 0;
		int number = 0;
		bool isneg = false;
		// trimleft
		while (idx != str.length()){
			if (isWhiteSpace(str[idx])){
				idx++;
			}
			else break;
		}
		if (str[idx] == '-') {
			isneg = true;
			++idx;
		}
		else if (str[idx] == '+'){
			isneg = false;
			++idx;
		}
		string numbers;
		for (int i = idx; isDigit(str[i]); ++i){
			numbers.push_back(str[i]);
		}
		string maxstr = "2147483647", minstr = "2147483648";
		if (numbers.length() == maxstr.length()){
			if (isneg && numbers > minstr) return INT_MIN;
			if (!isneg && numbers > maxstr) return INT_MAX;
		}
		if (numbers.length() > maxstr.length()){
			if (isneg) return INT_MIN;
			else return INT_MAX;
		}
		for (unsigned int i = 0; i < numbers.size(); ++i){
			int tmp = number;
			number += pow(10, numbers.size() - i - 1)*(numbers[i] - '0');
		}
		return isneg ? -number : number;
	}
};

int main(int argc, char** argv){
	string test = "-+1";
	cout << Solution().atoi(test);
	return 0;
}